package ua.org.pslava.codingtest;

import ua.org.pslava.codingtest.delegates.CountCalculateDelegator;
import ua.org.pslava.codingtest.delegates.ICalculateDelegate;
import ua.org.pslava.codingtest.factory.ProductFactory;
import ua.org.pslava.codingtest.model.Product;

/**
 * Main class of Coding Test project. <br/>
 *
 * 
 * @author Vyacheslav Panasyuk.
 */
public class CodingApp {

    public static void main(String[] args) {

        if (args.length > 0 && args[0] != null) {
            ProductFactory productFactory = new ProductFactory();
            ICalculateDelegate calcDelegate = new CountCalculateDelegator();

            Product productA = new Product("A", calcDelegate);
            productA.addPrice(1, 1.25);
            productA.addPrice(3, 3.00);

            Product productB = new Product("B", calcDelegate);
            productB.addPrice(1, 4.25);

            Product productC = new Product("C", calcDelegate);
            productC.addPrice(1, 1.0);
            productC.addPrice(6, 5.0);

            Product productD = new Product("D", calcDelegate);
            productD.addPrice(1, 0.75);

            productFactory.addProduct(productA);
            productFactory.addProduct(productB);
            productFactory.addProduct(productC);
            productFactory.addProduct(productD);

            PointOfSaleTerminal testTerminal = new PointOfSaleTerminal();
            testTerminal.setProductFabric(productFactory);
            testTerminal.AddOrder(args[0]);
            Double result = testTerminal.calculateTotal();
            System.out.println("Order = " + args[0]);
            System.out.println("Result = " + result);
        } else {
            System.out.println("Order is empty! ");
        }
    }
}